package org.mat.ipaas.ucenter.service.api.system;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysFillRuleDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 填值规则
 */
@Api(tags = "填值规则")
@FeignClient(name = "mat-ipaas-ucenter-service", contextId = "sys-fill-rule-rest-api")
public interface SysFillRuleRestAPI {

    /**
     * 分页列表查询
     *
     * @param sysFillRuleDTO
     * @param pageNo
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "填值规则-分页列表查询", notes = "填值规则-分页列表查询")
    @GetMapping(value = "/sys/fillRule/list")
    MatApiResponse<?> queryPageList(@SpringQueryMap SysFillRuleDTO sysFillRuleDTO,
                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize);

    /**
     * 测试 ruleCode
     *
     * @param ruleCode
     * @return
     */
    @GetMapping(value = "/sys/fillRule/testFillRule")
    MatApiResponse testFillRule(@RequestParam("ruleCode") String ruleCode);

    /**
     * 添加
     *
     * @param sysFillRuleDTO
     * @return
     */
    @ApiOperation(value = "填值规则-添加", notes = "填值规则-添加")
    @PostMapping(value = "/sys/fillRule/add")
    MatApiResponse<?> add(@RequestBody SysFillRuleDTO sysFillRuleDTO);

    /**
     * 编辑
     *
     * @param sysFillRuleDTO
     * @return
     */
    @ApiOperation(value = "填值规则-编辑", notes = "填值规则-编辑")
    @RequestMapping(value = "/sys/fillRule/edit", method = {RequestMethod.POST})
    MatApiResponse<?> edit(@RequestBody SysFillRuleDTO sysFillRuleDTO);

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "填值规则-通过id删除", notes = "填值规则-通过id删除")
    @DeleteMapping(value = "/sys/fillRule/delete")
    MatApiResponse<?> delete(@RequestParam(name = "id", required = true) String id);

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "填值规则-批量删除", notes = "填值规则-批量删除")
    @DeleteMapping(value = "/sys/fillRule/deleteBatch")
    MatApiResponse<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids);

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "填值规则-通过id查询", notes = "填值规则-通过id查询")
    @GetMapping(value = "/sys/fillRule/queryById")
    MatApiResponse<?> queryById(@RequestParam(name = "id", required = true) String id);

    /**
     * 导出excel
     *
     * @param sysFillRuleDTO
     */
    @RequestMapping(value = "/sys/fillRule/exportXls")
    ModelAndView exportXls(SysFillRuleDTO sysFillRuleDTO);

    /**
     * 通过excel导入数据
     *
     * @return
     */
    @RequestMapping(value = "/sys/fillRule/importExcel", method = RequestMethod.POST)
    MatApiResponse<?> importExcel();

    /**
     * 通过 ruleCode 执行自定义填值规则
     *
     * @param ruleCode 要执行的填值规则编码
     * @param formData 表单数据，可根据表单数据的不同生成不同的填值结果
     * @return 运行后的结果
     */
    @PutMapping("/sys/fillRule/executeRuleByCode/{ruleCode}")
    MatApiResponse executeByRuleCode(@PathVariable("ruleCode") String ruleCode, @RequestBody JSONObject formData);


    /**
     * 批量通过 ruleCode 执行自定义填值规则
     *
     * @param ruleData 要执行的填值规则JSON数组：
     *                 示例： { "commonFormData": {}, rules: [ { "ruleCode": "xxx", "formData": null } ] }
     * @return 运行后的结果，返回示例： [{"ruleCode": "order_num_rule", "result": "CN2019111117212984"}]
     */
    @PutMapping("/sys/fillRule/executeRuleByCodeBatch")
    MatApiResponse executeByRuleCodeBatch(@RequestBody JSONObject ruleData);

}